<?php
	$user = $controller->getCurrentUser();
	//on verifie les permissions
	if ($user->isAllowedTo(GRADE_MOD_BOOK))
	{    
	
		$book = new book();
		$edition = new edition();
		$album = new album();
		$book->setAlbumObject($album);
		$book->setEditionObject($edition);
		
		//on renseigne l'objet book
		if ($condition = $request->getParam('bookCondition'))                                                       $book->setCondition($condition);
		if (($publisherId = $request->getParam('publisherId')) && isset($publisherId) && is_numeric($publisherId))  $book->setIdpublisher($publisherId);
		if (($serie = $request->getParam('serie')) && isset($serie) && is_numeric($serie) )                         $book->setIdserie($serie);
		if ($description = $request->getParam('bookDescription'))                                                   $book->setDescription($description);
		if (($price = $request->getParam('bookPrice')) && isset($price) && is_numeric($price))                      $book->setPrice($price);
		if ($year = $request->getParam('bookYear'))                                                                 $book->setYear($year);
		if ($EAN13 = $request->getParam('bookEan13'))                                                               $book->setEan13($EAN13);
		if ($emplacement = $request->getParam('bookEmplacement'))                                                   $book->setLocation($emplacement);
		if ($cotation = $request->getParam('bookCotation'))                                                         $book->setCotation($cotation);
		if ($parutionDate = $request->getParam('bookParutionDate'))                                                 $book->setParution($parutionDate);
		if (($tome = $request->getParam('bookTome')) && isset($tome) && is_numeric($tome))                          $book->setTome($tome);
		if ($name = $request->getParam('bookName'))                                                                 $book->setName($name);
		if ($drawerList = $request->getParam('drawerList'))                                                         $book->setDrawerList($drawerList);
		if ($scriptWritterList = $request->getParam('scriptWritterList'))                                           $book->setScriptWritterList($scriptWritterList);
		
		//si tout est OK, on ajoute
		if ($book->isReadyToAdd())
		{
			$request->clean('post');
			$book->add();
			$logPermAction = 'BD ajout&eacute;e  : '.addslashes($book->getName());
			logPermactions($user->getId(), $logPermAction);
			$controller->addInformation('L\'album a bien &eacute;t&eacute; enregistr&eacute; !');
		}
		else //sinon on balance une erreur
			$controller->addError('Veuillez remplir les champs necessaires !');	
		//et on forward
		$controller->forward('addBook');
	}
	else
		$controller->render('errorRights');
  
?>
